from recordclass import recordclass

from coin.exchange.base.order_fill_util import FillManager

_BitfinexOrderInternal = recordclass(
    'BitfinexOrderInternal',
    ['server_order_id', 'group_id', 'fill', 'timestamp_created', 'maker', 'foreign'])


class BitfinexOrderInternal(_BitfinexOrderInternal):
  @staticmethod
  def create_by_submit(*, price_orig, qty_orig, timestamp_created):
    return BitfinexOrderInternal._create(price_orig=price_orig,
                                         qty_orig=qty_orig,
                                         timestamp_created=timestamp_created)

  @staticmethod
  def create_by_order_update(*,
                             price_orig,
                             qty_orig,
                             server_order_id,
                             group_id,
                             timestamp_created,
                             foreign):
    return BitfinexOrderInternal._create(price_orig=price_orig,
                                         qty_orig=qty_orig,
                                         server_order_id=server_order_id,
                                         group_id=group_id,
                                         timestamp_created=timestamp_created,
                                         foreign=foreign)

  @staticmethod
  def create_by_trade_event(*,
                            price_orig=None,
                            qty_orig=None,
                            server_order_id=None,
                            timestamp_created=None,
                            maker=None):
    return BitfinexOrderInternal._create(price_orig=price_orig,
                                         qty_orig=qty_orig,
                                         server_order_id=server_order_id,
                                         timestamp_created=timestamp_created,
                                         maker=maker)

  @staticmethod
  def _create(*,
              timestamp_created,
              price_orig=None,
              qty_orig=None,
              server_order_id=None,
              group_id=None,
              maker=None,
              foreign=None):
    return BitfinexOrderInternal(server_order_id=server_order_id,
                                 group_id=group_id,
                                 fill=FillCollector(price_orig=price_orig, qty_orig=qty_orig),
                                 timestamp_created=timestamp_created,
                                 maker=maker,
                                 foreign=foreign)
